package bintree.leetcode;

import java.util.HashMap;
import java.util.Map;

public class Num1_两数之和 {
    public int[] twoSum(int[] nums, int target) {
        int[] ret = new int[2];
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i],i );
            if (map.containsKey(target-nums[i])){
                ret[0]=map.get(target-nums[i]);
                ret[1]=i;
            }
        }
        return  ret;
    }
}
